package com.asia5b.a5mall.middleware.api

import com.asia5b.a5mall.middleware.config.GlobalValue

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   Url控制器接口
 * 根地址
 */
interface UrlManager {

    /// host地址
    val base: String

    /// 买家
    val buyer: String

    /// 基础Api
    val basic: String

    /**
     * @Note   伴生对象
     */
    companion object {

        /**
         * @Note   构架Url控制器
         */
        fun build(): UrlManager {
            return if (GlobalValue.appType == 0) {
                val devUrlManager = DevUrlManager()
                return devUrlManager
            } else {
                return ProUrlManager()
            }
        }

    }

}

/**
 * @Note   开发模式Url控制器
 */
private class DevUrlManager : UrlManager {

    val baseUrl = "https://apimall.asiajy.com/%s/"//测试地址
    //    val baseUrl="http://192.168.2.155:%s/"//朱工
//        val baseUrl="http://192.168.2.120:%s/"//锦工
//    val baseUrl="http://47.88.223.5:%s/"//测试地址
//    val baseUrl="http://javashop7.s1.natapp.cc/"//外包给的测试地址

    override val base = baseUrl

    val buyerSuffix = "buyer"//测试地址后缀
//    val buyerSuffix = "7002"//测试地址后缀

    override val buyer = String.format(base, buyerSuffix)

    val basicSuffix = "base"//测试地址后缀
//    val basicSuffix = "7000"//测试地址后缀

    override val basic = String.format(base, basicSuffix)

}

/**
 * @Note   生产模式Url控制器
 */
private class ProUrlManager : UrlManager {

    override val base: String
        get() = "https://apimall.a5bmall.com/%s/"
//        get() = "http://api.%s.javamall.com.cn/"

    override val buyer = String.format(base, "buyer")

    override val basic = String.format(base, "base")
}
/*

base: 'https://apimall.a5bmall.com/base',
buyer: 'https://apimall.a5bmall.com/buyer',
seller: 'https://apimall.a5bmall.com/seller',
admin: 'https://apimall.a5bmall.com/manager'

dev: {
    base: 'https://apimall.asiajy.com/base',
    buyer: 'https://apimall.asiajy.com/buyer',
    seller: 'https://apimall.asiajy.com/seller',
    admin: 'https://apimall.asiajy.com/manager'
},

        */